import _ from 'lodash'

const convertIdListToObjList = function (idList, baseList) {
  if (idList.length === 0 || baseList.length === 0) {
    return []
  }

  let objList = [];
  let tempWorkouts = {};

  idList.forEach(item => {
    if(tempWorkouts[item]) {
      objList.push(tempWorkouts[item])
    } else {
      let workout = _.find(baseList, ['id', item]);
      tempWorkouts[workout.id] = workout;
      objList.push(workout);
    }
  })

  return objList
}

const convertObjListToIdList = function (objList) {
  if (objList.length === 0) {
    return []
  }

  let idList = []
  objList.forEach((item) => idList.push(item.id))

  return idList
}

export default {
  convertIdListToObjList,
  convertObjListToIdList
}
